<template>
  <div class="course-content">
    <!-- 顶部轮播图 -->
    <van-swipe class="my-swipe" :autoplay="3000" indicator-color="pink">
      <van-swipe-item
        v-for="item in activedList"
        :key="item.id"
      >
        <img :src="item.img" alt="">
      </van-swipe-item>
    </van-swipe>
    <!-- 底部课程列表 -->
    <course-content-list
      :fetchData="fetchData"
    ></course-content-list>
  </div>
</template>

<script>
import { Swipe, SwipeItem } from 'vant'
import CourseContentList from '@/components/CourseContentList'
import { getAllAds, getQueryCourses } from '@/services/course'

export default {
  name: 'CourseContent',
  components: {
    CourseContentList,
    VanSwipe: Swipe,
    VanSwipeItem: SwipeItem
  },
  data () {
    return {
      // 轮播图图片列表
      adList: []
    }
  },
  created () {
    // 请求轮播图图片信息
    this.loadAds()
  },
  methods: {
    fetchData (options) {
      return getQueryCourses(options)
    },
    async loadAds () {
      const { data } = await getAllAds({
        // 999 代表着首页顶部轮播图的广告位
        spaceKeys: '999'
      })
      // 存储到 adList
      this.adList = data.content[0].adDTOList
    }
  },
  computed: {
    activedList () {
      return this.adList.filter(item => item.status === 1)
    }
  }
}
</script>

<style lang="scss" scoped>
.my-swipe {
  width: 100%;
}

.my-swipe .van-swipe-item {
  display: flex;
  justify-content: center;
  overflow: hidden;
}

.my-swipe img {
  height: 170px;
}

.course-content-list {
  top: 220px;
  bottom: 50px;
}
</style>
